package reflect;

import reflect.annotation.AutoRunClass;
import reflect.annotation.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;
import java.util.Set;

//调用Person中所有被注解@AutoRunMethod标注的方法
public class Test4 {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String className = scan.nextLine();
        Class cls = Class.forName(className);
        if (cls.isAnnotationPresent(AutoRunClass.class)) {
            Object obj = cls.newInstance();
            Method[] methods = cls.getMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(AutoRunMethod.class)) {
                    method.invoke(obj);
                }
            }
        } else {
            System.out.println("该类没有被注解@AutoRunClass标注");
        }
    }
}